var server_config=require("../server_config");
var netbus=require("../../netbus/netbus");
var service_manager=require("../../netbus/service_manager");
var gatewayModule=require("./gatewayModule");
var broadcastModule=require("./broadcastModule");

//启动网关服务器
var gatway=server_config.gateway;

if (gatway.ntype==server_config.NetType.TCP)
	netbus.tcp_server(gatway.host,gatway.port,true);
else
	netbus.ws_server(gatway.host,gatway.port,true);


//注册广播模块
service_manager.register_service(server_config.Stype.Broadcast, broadcastModule);


//连接app服务器
for (var key in server_config){
	if (server_config[key].stypes){

		var app_server=server_config[key];

		for(var skey in app_server.stypes){

			var stype=app_server.stypes[skey];

			if (app_server.ntype==server_config.NetType.TCP)
				netbus.connect_tcp_app_server(stype,app_server.host,app_server.port,false);
			else
				netbus.connect_ws_app_server(stype,app_server.host,app_server.port,false);

			//注册与app服务器收发消息的处理函数
			service_manager.register_service(stype,gatewayModule);
		}

	}
}


